package cn.sunshine.ymcc.web.controller;

import cn.sunshine.ymcc.CourseDoc;
import cn.sunshine.ymcc.dto.CourseESSearchDto;
import cn.sunshine.ymcc.result.JSONResult;
import cn.sunshine.ymcc.result.PageList;
import cn.sunshine.ymcc.service.ICourseEsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/course")
public class CourseEsController{
    @Autowired
    private ICourseEsService courseEsService;
    @PostMapping("/save")
    @PreAuthorize("hasAuthority('es:saveCourse')")
    public JSONResult saveCourse(@RequestBody CourseDoc doc){
        courseEsService.saveCourse(doc);
        return JSONResult.success();
    }

    @PostMapping("/{id}")
    public JSONResult delete(@PathVariable("id") Long id){
        courseEsService.delete(id);
        return JSONResult.success();
    }
    /*
    * @Title: search
    * @Description: 分页搜索
    * @Author: Mr.Jiang
    * @Version: 1.0
    * @Date:  2022/8/15 12:40
    * @Parameters: [courseESSearchDto]
    * @Return cn.sunshine.ymcc.result.JSONResult
    */
    @PostMapping("/search")
    public JSONResult search(@RequestBody CourseESSearchDto courseESSearchDto){
        PageList<CourseDoc> search = courseEsService.search(courseESSearchDto);
        return JSONResult.success(search);
    }
}
